package com.dao;
import java.sql.*;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class DbConn {
	private String sDBriver="com.mysql.cj.jdbc.Driver";
	private String sConnStr="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
	private String sUsername="root",sPassword="123";
	protected Connection conn=null;
	
	public DbConn() {
		 Connection con = null;
		 try {
		Context ctx = new InitialContext();
		DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/test");
		con=ds.getConnection();
		if (con==null) System.out.println("connection is null");
		 }
		 catch (Exception e) {
		 String log ="Proc " + this.getClass() + " connection failure:\r\n"+e.getMessage()+"\r\n";
		System.out.println(log);
		 }
		this.conn = con;
	}

	public void close()
	{
		try {
			if(conn!=null)
				conn.close();
			
		}catch(SQLException e) {
			System.out.println(e.getMessage());
		}
	}
}
